/**
 * Created by alan on 2017/4/27.
 * 水库基本信息
 */
Ext.define('Admin.view.waterDispath.ReservoirBaseController', {
  extend: 'Ext.app.ViewController',
  alias: 'controller.reservoirBaseController',

  init: function() {
    // Ext.Ajax.request({
    //   url: "test.json"
    // })
  },

  //steps下一步
  check: function() {
    var reservoirGrid = this.lookupReference('reservoirGrid');
    var store  = reservoirGrid.getStore();
    var resNm = this.lookupReference('resNm').getValue();

    store.getProxy().extraParams = {river:config.RIVER,resNm: resNm};
    store.reload();
  },
//水位库容
  toChart : function(grid,rowIndex,columnIndex,e){
    var methis = this;
    var record = grid.getStore().getAt(rowIndex);
  //  var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
    var resCd = record.get('resCd');
    var resNm = record.get('resNm');
    var win = Ext.create('Ext.window.Window', {
	    title: resNm+'水位库容曲线',
	    height: 720,
	    width: 1000,
//	    modal:false,
	    layout: 'fit',
	    items: [{
            xtype:'textfield',
            hidden:true,
            value:resCd,
            id:'resCd',
            fieldLabel: '水库代码',
            reference: 'resCd',
        },{
              xtype:'textfield',
              hidden:true,
              value:resNm,
              id:'resNm',
              fieldLabel: '水库名称',
              reference: 'resNm',
          },{  // Let's put an empty grid in just to illustrate fit layout
	        xtype: 'ddsBResChart',
	        border: false
	    }]
	}).show();
},
//下泄尾水
toChartTail : function(grid,rowIndex,columnIndex,e){
  var methis = this;
  var record = grid.getStore().getAt(rowIndex);
//  var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
  var resCd = record.get('resCd');
  var resNm = record.get('resNm');
  var win = Ext.create('Ext.window.Window', {
    title: resNm+'下泄尾水曲线',
    height: 720,
    width: 1000,
//  modal:false,
    layout: 'fit',
    items: [{
          xtype:'textfield',
          hidden:true,
          value:resCd,
          id:'resCd',
          fieldLabel: '水库代码',
          reference: 'resCd',
      },{
            xtype:'textfield',
            hidden:true,
            value:resNm,
            id:'resNm',
            fieldLabel: '水库名称',
            reference: 'resNm',
        },{  // Let's put an empty grid in just to illustrate fit layout
        xtype: 'ddsBResTailChart',
        border: false
    }]
}).show();
},
});

/**
 * Created by alan on 2017/5/16.
 * 水库水位库容曲线关系
 */
Ext.define('Admin.view.waterDispath.DdsBResChartController', {
  extend: 'Ext.app.ViewController',
  alias: 'controller.ddsBResChartController',

  init: function() {

  },


initLoad:function(){
  var me = this ;
  var grid = me.lookupReference('ddsBResChartGrid');
  var store = grid.getStore();
  var resCd = Ext.getCmp('resCd').getValue();
  var resNm = Ext.getCmp('resNm').getValue();
  store.getProxy().extraParams = {resCd: resCd};
  store.reload();
  var v0 = [];
  var v1=[];
  store.on("load", function() {
      v0=[],v1=[];
     for (var i = 0 ; i < store.getCount();i++){
      var vv0 = store.getAt(i).get("v0");
      var vv1 = store.getAt(i).get("v1");
      if(vv0&&vv0!=""&&vv1&&vv1!=""){
        v0.push(vv0);
        v1.push(parseFloat(vv1));
      }
    }
    var chart_title = resNm+'水位库容曲线';
    var chart_xAxisCate = v0;
    var chart_serieData = [{
            name: '水位：m ',
            data: v1
        }
    ];
     me.initChart(chart_title,chart_xAxisCate,chart_serieData);

  });


},
  // init chart
  initChart: function (title, xAxisCate, serieData) {
    $('#myChart').highcharts({
        chart: {
            type: 'spline'
        },
        title: {
            text: title
        },
        xAxis: {
            min: 0,
            gridLineWidth: 0,
            title: {
                text: '库容 百万<su>3</sup>'
            }
        },
        yAxis: {
          categories: xAxisCate,
          label:{
            step:11
          },
          title: {
              text: '水位'
          }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">库容:{point.key} 百万m<sup>3</sup> </span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">水位: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} m</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: serieData,
        credits: { enabled:false }
    });
  },
  find:function(){
    var me = this ;
    var ddsBResChartGrid = this.lookupReference('ddsBResChartGrid');
    var store  = ddsBResChartGrid.getStore();
    var v0 = this.lookupReference('v0').getValue();
    var v1 = this.lookupReference('v1').getValue();
    var resCd = Ext.getCmp('resCd').getValue();
    store.getProxy().extraParams = {river:config.RIVER,v0: v0, v1:v1,resCd:resCd};
    store.reload();

  }
});

/**
 * Created by alan on 2017/5/16.
 * 水库下泄尾水曲线关系图
 */
Ext.define('Admin.view.waterDispath.DdsBResTailChartController', {
  extend: 'Ext.app.ViewController',
  alias: 'controller.ddsBResTailChartController',

  init: function() {

  },


initLoad:function(){
  var me = this ;
  var grid = me.lookupReference('ddsBResTailChartGrid');
  var store = grid.getStore();
  var resCd = Ext.getCmp('resCd').getValue();
  var resNm = Ext.getCmp('resNm').getValue();
  store.getProxy().extraParams = {river:config.RIVER,resCd: resCd};
  store.reload();
  var v0 = [];
  var v1=[];
  store.on("load", function() {
      v0=[],v1=[];
     for (var i = 0 ; i < store.getCount();i++){
      var vv0 = store.getAt(i).get("v0");
      var vv1 = store.getAt(i).get("v1");
      if(vv0&&vv0!=""&&vv1&&vv1!=""){
        v0.push(vv0);
        v1.push(parseFloat(vv1));
      }
    }
    var chart_title = resNm+'下泄尾水曲线';
    var chart_xAxisCate = v0;
    var chart_serieData = [{
            name: '水位：m ',
            data: v1
        }
    ];
     me.initChart(chart_title,chart_xAxisCate,chart_serieData);
  });


},
  // init chart
  initChart: function (title, xAxisCate, serieData) {
    $('#myChart').highcharts({
        chart: {
            type: 'spline'
        },
        title: {
            text: title
        },
        xAxis: {
            min: 0,
            // tickInterval: 100,
            gridLineWidth: 0,
            title: {
                text: '流量 百万<su>3</sup>'
            }
        },
        yAxis: {
            categories: xAxisCate,
            label:{
              step:11
            },
            title: {
                text: '水位'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">流量:{point.key} 百万m<sup>3</sup>/s </span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">水位: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} m</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: serieData,
        credits: { enabled:false }
    });
  },
  find:function(){
    var me = this ;
    var ddsBResChartGrid = this.lookupReference('ddsBResTailChartGrid');
    var store  = ddsBResChartGrid.getStore();
    var v0 = this.lookupReference('v0').getValue();
    var v1 = this.lookupReference('v1').getValue();
    var resCd = Ext.getCmp('resCd').getValue();
    store.getProxy().extraParams = {river:config.RIVER,v0: v0, v1:v1,resCd:resCd};
    store.reload();

  }
})
